/**
 * @file   generator.cpp
 * @author ywl <ywl@ywl-VirtualBox>
 * @date   Fri Nov 25 23:00:06 2022
 * 
 * @brief  A program to generate random numbers.
 * 
 * 
 */

#include<iostream>
#include<fstream>
#include<ctime>
#include<cstdlib>
using namespace std;

/** 
 * 
 * 
 * @param begin 
 * @param end 
 * 
 * @return 
 */
int RandNumber(int begin, int end)
{
    return (rand()%(end-begin+1))+begin;
} 

int main(int argc, char *argv[])
{
    srand(time(0));
    if (argc < 2)
    {
	cerr << "Input params not enough!" << endl;
	exit(-1);
    }
    cout << "Generate " << argv[1] << " numbers" << endl;
    int number = atoi(argv[1]);
    // Output data to file
    ofstream file;
    file.open("number.txt",ios_base::out);
    if (file.fail())
    {
	cerr << "Open Error!" << endl;
	exit(-1);
    }
    
    // Generate random integers and output
    for (int i = 0; i < number; ++i){
        file << RandNumber(-50000,50000);
	if(i != (number - 1))
	    file << " ";
    }
    
    return 0;
}
